package com.scwuhua.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.PageUtils;
import com.scwuhua.dto.IntegratedData;
import com.scwuhua.dto.MeteorologicalSoilListDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.scwuhua.domain.MeteorologicalSoil;
import com.scwuhua.service.IMeteorologicalSoilService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据查询Controller
 * 
 * @author wuhua
 * @date 2023-05-06
 */
@Slf4j
@RestController
@RequestMapping("/system/weather")
public class MeteorologicalSoilController extends BaseController
{
    @Autowired
    private IMeteorologicalSoilService meteorologicalSoilService;

    /**
     * 查询数据查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:weather:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeteorologicalSoil meteorologicalSoil)
    {
        startPage();
        IntegratedData integratedData = meteorologicalSoilService.selectMeteorologicalSoilList(meteorologicalSoil);

        return getNewDataTable(integratedData.getMeteorologicalSoilListData(),integratedData.getTotal());
    }




    /**
     * 导出数据查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:weather:export')")
    @Log(title = "数据查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeteorologicalSoil meteorologicalSoil)
    {
        IntegratedData integratedData = meteorologicalSoilService.selectMeteorologicalSoilList(meteorologicalSoil);
        List<MeteorologicalSoilListDto> meteorologicalSoilListData = integratedData.getMeteorologicalSoilListData();
        ExcelUtil<MeteorologicalSoilListDto> util = new ExcelUtil<MeteorologicalSoilListDto>(MeteorologicalSoilListDto.class);

        util.exportExcel(response, meteorologicalSoilListData, "数据查询数据");
    }
    /**
    * 查询当日数据
    * */
    @GetMapping("/onThatDay")
    public AjaxResult dayData(MeteorologicalSoil meteorologicalSoil){
         List<MeteorologicalSoil> dayMeteorologicalSoils = meteorologicalSoilService.dayData(meteorologicalSoil);
         return success(dayMeteorologicalSoils);
    }

    /**
     * 查询最新数据
     * */
    @GetMapping("/newest")
     public AjaxResult newestData(MeteorologicalSoil meteorologicalSoil){
        MeteorologicalSoilListDto ms = meteorologicalSoilService.newestData(meteorologicalSoil);
        log.info(ms+"返回最新数据");
        return success(ms);
     }

     /**
      * 一键同步功能
      * */
     @GetMapping("/synchroData")
     public AjaxResult synchroData(){
         return toAjax(meteorologicalSoilService.synchroData());
     }







    /**
     * 获取数据查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:weather:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(meteorologicalSoilService.selectMeteorologicalSoilById(id));
    }

    /**
     * 新增数据查询
     */
    @PreAuthorize("@ss.hasPermi('system:weather:add')")
    @Log(title = "数据查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeteorologicalSoil meteorologicalSoil)
    {
        return toAjax(meteorologicalSoilService.insertMeteorologicalSoil(meteorologicalSoil));
    }

    /**
     * 修改数据查询
     */
    @PreAuthorize("@ss.hasPermi('system:weather:edit')")
    @Log(title = "数据查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeteorologicalSoil meteorologicalSoil)
    {
        return toAjax(meteorologicalSoilService.updateMeteorologicalSoil(meteorologicalSoil));
    }

    /**
     * 删除数据查询
     */
    @PreAuthorize("@ss.hasPermi('system:weather:remove')")
    @Log(title = "数据查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(meteorologicalSoilService.deleteMeteorologicalSoilByIds(ids));
    }
}
